Quickstart¶
In this tutorial, we will show how to solve a famous optimization problem, minimizing the Rosenbrock function, in simplenlopt. First, let’s define the Rosenbrock function and plot it:
\[f(x, y) = (1-x)^2+100(y-x^2)^2\]
[1]:
import numpy as np
def rosenbrock(pos):
x, y = pos
return (1-x)**2 + 100 * (y - x**2)**2
xgrid = np.linspace(-2, 2, 500)
ygrid = np.linspace(-1, 3, 500)
X, Y = np.meshgrid(xgrid, ygrid)
Z = (1 - X)**2 + 100 * (Y -X**2)**2
x0=np.array([-1.5, 2.25])
f0 = rosenbrock(x0)
import plotly.graph_objects as go
fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y, cmax = 10, cmin = 0, showscale = False)])
fig.update_layout(
scene = dict(zaxis = dict(nticks=4, range=[0,10])))
fig.add_scatter3d(x=[1], y=[1], z=[0], mode = 'markers', marker=dict(size=10, color='green'), name='Optimum')
fig.add_scatter3d(x=[-1.5], y=[2.25], z=[f0], mode = 'markers', marker=dict(size=10, color='black'), name='Initial guess')
#fig.update_traces(showlegend=False)
fig.show()